﻿#region | Copyright © 2013 Siriwat.Suananpornpanit |
/*
Author by : Siriwat.Suananpornpanit
DateTime  : 2013/08/26
Control for Toolbar access (add,edit,copy,delete,search)
Email : s2win@live.com
*/
#endregion

using System.ComponentModel;
using System.Web;
using Resources;
using AttributeCollection = System.Web.UI.AttributeCollection;

#region | Imports |

using System;

#endregion

#region | Source |

namespace Web.UserControls
{
    public partial class AccessControlToolbar : System.Web.UI.UserControl
    {

        private string _resource = "Resource";

        #region | Init Page Controls |

        protected void Page_Load(object sender, EventArgs e)
        {
            // Init Buttons
            btnAdd.Click += new EventHandler(btnAdd_Click);
            btnEdit.Click += new EventHandler(btnEdit_Click);
            btnCopy.Click += new EventHandler(btnCopy_Click);
            btnDelete.Click += new EventHandler(btnDelete_Click);
            btnSearch.Click += new EventHandler(btnSearch_Click);
            btnSave.Click += new EventHandler(btnSave_Click);
            btnCancel.Click += new EventHandler(btnCancel_Click);
        }

        protected void Page_Init(object sender, EventArgs e)
        {
           //
        }

        public AccessControlToolbar()
        {
           // Init += Init;
        }

        #endregion

        #region | ClientID |

        public string AddClientID
        {
            get { return this.btnAdd.ClientID; }
        }

        public string EditClientID
        {
            get { return this.btnEdit.ClientID; }
        }

        public string CopyClientID
        {
            get { return this.btnCopy.ClientID; }
        }

        public string DeleteClientID
        {
            get { return this.btnDelete.ClientID; }
        }

        public string SearchClientID
        {
            get { return this.btnSearch.ClientID; }
        }

        public string SaveClientID
        {
            get { return btnSave.ClientID; }
        }

        public string CancelClientID
        {
            get { return btnCancel.ClientID; }
        }

        #endregion

        #region | Text |

        public string AddText
        {
            get { return this.btnAdd.Text; }
            set { this.btnAdd.Text = GetResource(value); }
        }

        public string EditText
        {
            get { return this.btnEdit.Text; }
            set { this.btnEdit.Text = GetResource(value); }
        }

        public string CopyText
        {
            get { return this.btnCopy.Text; }
            set { this.btnCopy.Text = GetResource(value); }
        }

        public string DeleteText
        {
            get { return this.btnDelete.Text; }
            set { this.btnDelete.Text = GetResource(value); }
        }

        public string SearchText
        {
            get { return this.btnSearch.Text; }
            set { this.btnSearch.Text = GetResource(value); }
        }

        public string SaveText
        {
            get { return this.btnSave.Text; }
            set { this.btnSave.Text = GetResource(value); }
        }

        public string CancelText
        {
            get { return this.btnCancel.Text; }
            set { this.btnCancel.Text = GetResource(value); }
        }
        #endregion

        #region | ToolTip |

        public string AddToolTip
        {
            get { return this.btnAdd.ToolTip; }
            set { this.btnAdd.ToolTip = GetResource(value); }
        }

        public string EditToolTip
        {
            get { return this.btnEdit.ToolTip; }
            set { this.btnEdit.ToolTip = GetResource(value); }
        }

        public string CopyToolTip
        {
            get { return this.btnCopy.ToolTip; }
            set { this.btnCopy.ToolTip = GetResource(value); }
        }

        public string DeleteToolTip
        {
            get { return this.btnDelete.ToolTip; }
            set { this.btnDelete.ToolTip = GetResource(value); }
        }

        public string SearchToolTip
        {
            get { return this.btnSearch.ToolTip; }
            set { this.btnSearch.ToolTip = GetResource(value); }
        }

        public string SaveToolTip
        {
            get { return this.btnSave.ToolTip; }
            set { this.btnSave.ToolTip = GetResource(value); }
        }

        public string CancelToolTip
        {
            get { return this.btnCancel.ToolTip; }
            set { this.btnCancel.ToolTip = GetResource(value); }
        }
        #endregion

        #region | Enable |

        public bool AddEnabled
        {
            get { return this.btnAdd.Enabled; }
            set { this.btnAdd.Enabled = value; }
        }

        public bool EditEnabled
        {
            get { return this.btnEdit.Enabled; }
            set { this.btnEdit.Enabled = value; }
        }

        public bool CopyEnabled
        {
            get { return this.btnCopy.Enabled; }
            set { this.btnCopy.Enabled = value; }
        }

        public bool DeleteEnabled
        {
            get { return this.btnDelete.Enabled; }
            set { this.btnDelete.Enabled = value; }
        }

        public bool SearchEnabled
        {
            get { return this.btnSearch.Enabled; }
            set { this.btnSearch.Enabled = value; }
        }

        public bool SaveEnabled
        {
            get { return this.btnSave.Enabled; }
            set { this.btnSave.Enabled = value; }
        }

        public bool CancelEnabled
        {
            get { return this.btnCancel.Enabled; }
            set { this.btnCancel.Enabled = value; }
        }
        #endregion

        #region | Visible |

        public bool AddVisible
        {
            get { return this.btnAdd.Visible; }
            set
            {
                this.btnAdd.Visible = value;
                this.liAdd.Visible = value;
            }
        }

        public bool EditVisible
        {
            get { return this.btnEdit.Visible; }
            set
            {
                this.btnEdit.Visible = value;
                this.liEdit.Visible = value;
            }
        }

        public bool CopyVisible
        {
            get { return this.btnCopy.Visible; }
            set
            {
                this.btnCopy.Visible = value;
                this.liCopy.Visible = value;
            }
        }

        public bool DeleteVisible
        {
            get { return this.btnDelete.Visible; }
            set
            {
                this.btnDelete.Visible = value;
                this.liDelete.Visible = value;
            }
        }

        public bool SearchVisible
        {
            get { return this.btnSearch.Visible; }
            set
            {
                this.btnSearch.Visible = value;
                this.liSearch.Visible = value;
            }
        }

        public bool SaveVisible
        {
            get { return this.btnSave.Visible; }
            set
            {
                this.btnSave.Visible = value;
                this.liSave.Visible = value;
            }
        }

        public bool CancelVisible
        {
            get { return this.btnCancel.Visible; }
            set
            {
                this.btnCancel.Visible = value;
                this.liCancel.Visible = value;
            }
        }
        #endregion

        #region | Attributes |

        public AttributeCollection AddAttributes
        {
            get { return this.btnAdd.Attributes; }
        }

        public AttributeCollection EditAttributes
        {
            get { return this.btnEdit.Attributes; }
        }

        public AttributeCollection CopyAttributes
        {
            get { return this.btnCopy.Attributes; }
        }

        public AttributeCollection DeleteAttributes
        {
            get { return this.btnDelete.Attributes; }
        }

        public AttributeCollection SearchAttributes
        {
            get { return this.btnSearch.Attributes; }
        }

        public AttributeCollection SaveAttributes
        {
            get { return this.btnSave.Attributes; }
        }

        public AttributeCollection CancelAttributes
        {
            get { return this.btnCancel.Attributes; }
        }

        #endregion

        #region | CssClass |

        public string AddCssClass
        {
            get { return this.btnAdd.CssClass; }
            set { this.btnAdd.CssClass = value; }
        }

        public string EditCssClass
        {
            get { return this.btnEdit.CssClass; }
            set { this.btnEdit.CssClass = value; }
        }

        public string CopyCssClass
        {
            get { return this.btnCopy.CssClass; }
            set { this.btnCopy.CssClass = value; }
        }

        public string DeleteCssClass
        {
            get { return this.btnDelete.CssClass; }
            set { this.btnDelete.CssClass = value; }
        }

        public string SearchCssClass
        {
            get { return this.btnSearch.CssClass; }
            set { this.btnSearch.CssClass = value; }
        }

        public string SaveCssClass
        {
            get { return this.btnSave.CssClass; }
            set { this.btnSave.CssClass = value; }
        }

        public string CancelCssClass
        {
            get { return this.btnCancel.CssClass; }
            set { this.btnCancel.CssClass = value; }
        }

        #endregion

        #region | Events |

        public event AddEventHandler AddClick;

        public event EditEventHandler EditClick;

        public event CopyEventHandler CopyClick;

        public event DeleteEventHandler DeleteClick;

        public event SearchEventHandler SearchClick;

        public event SaveEventHandler SaveClick;

        public event CancelEventHandler CancelClick;

        #endregion

        #region | Delegate |

        public delegate void AddEventHandler(object sender, EventArgs e);

        public delegate void EditEventHandler(object sender, EventArgs e);

        public delegate void CopyEventHandler(object sender, EventArgs e);

        public delegate void DeleteEventHandler(object sender, EventArgs e);

        public delegate void SearchEventHandler(object sender, EventArgs e);

        public delegate void SaveEventHandler(object sender, EventArgs e);

        public delegate void CancelEventHandler(object sender, EventArgs e);

        #endregion

        #region | Click Able |

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (AddClick != null) AddClick(this, e);
        }

        protected void btnEdit_Click(object sender, EventArgs e)
        {
            if (EditClick != null) EditClick(this, e);
        }

        protected void btnCopy_Click(object sender, EventArgs e)
        {
            if (CopyClick != null) CopyClick(this, e);
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (DeleteClick != null) DeleteClick(this, e);
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            if (SearchClick != null) SearchClick(this, e);
        }

        public void btnSave_Click(object sender, EventArgs e)
        {
            if (SaveClick != null) SaveClick(this, e);
        }

        public void btnCancel_Click(object sender, EventArgs e)
        {
            if (CancelClick != null) CancelClick(this, e);
        }

        #endregion

        #region | Resources |

        public string Resource
        {
            set { _resource = value; }
        }

        public string GetResource(string resource, string value)
        {
            string r = Core.ResourceTools.GetResource(resourceKey: value) as string;
            if (r == null)
                return value;
            return r;
        }

        public string GetResource(string value)
        {
            string r = Core.ResourceTools.GetResource(resourceKey: value) as string;
            if (r == null)
                return value;
            return r;
        }
        #endregion
    }
}

#endregion